package authorization.firewall;
import java.util.Properties;

import com.rational.test.ft.object.interfaces.TestObject;

import core.Functions;
import core.PropertiesContainer;
import core.controls.Button;
import core.controls.TextField;
import core.exceptions.ResultFailureException;
import core.properties.PropertyReader;
import core.properties.RegisteredProperty;
import core.testcases.TestProjectSuperHelper;
import enums.ButtonType;
import enums.TextFieldType;
/**
 * Description   : Functional Test Script
 * @author angel.tsvetkov
 */
public class Authorization extends TestProjectSuperHelper
{
	public static boolean passMeThroughTheFirewall()
	{
		boolean result = true;
		try
		{
			PropertiesContainer propContainer = PropertiesContainer.getInstance();
			
			String url = propContainer.getFirewallURL();
			String user = propContainer.getFirewallUsername();
			String userPropValue = propContainer.getFirewallUPropValue();
			String userPropName = propContainer.getFirewallUPropName();
			
			String pass = propContainer.getFirewallPassword();
			String passPropValue = propContainer.getFirewallPPropValue();
			String passPropName = propContainer.getFirewallPPropName();
			
			String butPropValue = propContainer.getFirewallButPropValue();
			String butPropName = propContainer.getFirewallButPropName();
			
			startBrowser(url);
			TimeWait(4);
			
			//Have to be called after opening of the browser
			TestObject parent = getRootTestObject().find(atDescendant(".class", "Html.HtmlBrowser"))[0];
			
			TextField USERNAME_TEXTBOX = new TextField(userPropValue, userPropName, TextFieldType.textfield.getType(), parent, "User Name Text Box");
			
			TextField PASSWORD_TEXTBOX = new TextField(passPropValue, passPropName, TextFieldType.password.getType(), parent, "Password Text Box");
			
			Button CONTINUE_BUTTON = new Button(butPropValue, butPropName, ButtonType.submit.getType(), parent, "Login button");
			
			int ENCRYPT_MASK = 69;
			
			//Fill user name
			USERNAME_TEXTBOX.enter(user);
			
			//Fill password
			PASSWORD_TEXTBOX.enter(Functions.encrypt(pass, ENCRYPT_MASK));
			
			//Press continue button
			CONTINUE_BUTTON.click();
		}
		catch(ResultFailureException ex)
		{
			result = false;
			setErrorComment("Problem appear in authorization process.", ex);
		}
		
		return result;
	}
	
    public void testMain(Object[] args)
    {
    	passMeThroughTheFirewall();
    }
}

